package com.xiaoshuidi.cloud.module.contract.controller.admin.contract;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.controller.admin.contract.vo.ContractConfigReqVO;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.contract.ContractConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 合同配置")
@RestController
@RequestMapping(ApiConstants.NAME +"/config")
@Validated
public class ContractConfigController {
    @Resource
    private ContractConfigService contractConfigService;

    @PostMapping("/create")
    @Operation(summary = "创建合同配置")
    //@PreAuthorize("@ss.hasPermission('contract-config::create')")
    public CommonResult<Boolean> create(@Valid @RequestBody ContractConfigReqVO contractConfigReqVo) {
        contractConfigService.createContractConfig(contractConfigReqVo);
        return success(true);
    }

    @PostMapping("/save")
    @Operation(summary = "保存合同配置")
    //@PreAuthorize("@ss.hasPermission('contract-config::save')")
    public CommonResult<Boolean> save(@Valid @RequestBody ContractConfigReqVO contractConfigReqVo) {
        contractConfigService.saveContractConfig(contractConfigReqVo);
        return success(true);
    }

    @GetMapping("/get-contract-config")
    @Operation(summary = "获得合同配置信息")
    //@PreAuthorize("@ss.hasPermission('contract-config::create')")
    public CommonResult<ContractConfigReqVO> get() {
        return success(contractConfigService.getContractConfig());
    }
}
